import Vue from 'vue'
import Router from 'vue-router'
import index1 from "../views/login/index"
import {SetCookie ,GetCookie} from "@/config/config"
Vue.use(Router)

let RouterList = new Router({
  mode:"hash",
  routes: [
    {
      path: '/',
      name: 'index',
      component: index1,
      meta:{
        title:'金氏后台登录页面'
      },
      beforeEnter:(to , from,next)=>{
        console.log(from)
        console.log(to);
        next()
        //针对于项目中独特权限访问页面单独设立守卫
        // 以防用户本身有该权限
        // 但是在某一个又失去了权限而守卫拦截判断不给访问
      }
    },
    {
      path:"/home",
      name:"home",
      component:()=>import(`@/views/home/home`),
      redirect:"/workBench",
      children:[
        {
          path:"/workBench",
          name:"workBench",
          meta:{
            title:'工作台'
          },
          component:()=>import(`@/views/workBench/workBench`)
        },
        {
          path:"/typeApproval",
          name:"typeApproval",
          meta:{
            title:'审批类型'
          },
          component:()=>import(`@/views/basicData/typeApproval`)
        },
        {
          path:"/approvalProcess",
          name:"approvalProcess",
          meta:{
            title:'审批流程'
          },
          component:()=>import(`@/views/basicData/approvalProcess`)
        },
        {
          path:"/typePayment",
          name:"typePayment",
          meta:{
            title:'报销类型'
          },
          component:()=>import(`@/views/basicData/typePayment`)
        },
        {
          path:"/typeExpense",
          name:"typeExpense",
          meta:{
            title:'费用类型'
          },
          component:()=>import(`@/views/basicData/typeExpense`)
        },
        {
          path:"/enterpriseDominant",
          name:"enterpriseDominant",
          meta:{
            title:'企业主体'
          },
          component:()=>import(`@/views/basicData/enterpriseDominant`)
        },
        {
          path:"/typeIndustry",
          name:"typeIndustry",
          meta:{
            title:'行业类型'
          },
          component:()=>import(`@/views/basicData/typeIndustry`)
        },
        {
          path:"/typeWork",
          name:"typeWork",
          meta:{
            title:'工作类别'
          },
          component:()=>import(`@/views/basicData/typeWork`)
        },
        {
          path:"/typeService",
          name:"typeService",
          meta:{
            title:'服务类型'
          },
          component:()=>import(`@/views/basicData/typeService`)
        },
        {
          path:"/keyWord",
          name:"keyWord",
          meta:{
            title:'关键字'
          },
          component:()=>import(`@/views/basicData/keyWord`)
        },
        {
          path:"/departmentStructure",
          name:"departmentStructure",
          meta:{
            title:'部门架构'
          },
          component:()=>import(`@/views/hr/departmentStructure`)
        },
        {
          path:"/jobTitle",
          name:"jobTitle",
          meta:{
            title:'岗位职称'
          },
          component:()=>import(`@/views/hr/jobTitle`)
        },
        {
          path:"/firmEmployees",
          name:"firmEmployees",
          meta:{
            title:'企业员工'
          },
          component:()=>import(`@/views/hr/firmEmployees`)
        },
        {
          path:"/personnelTransfer",
          name:"personnelTransfer",
          meta:{
            title:'人事调动'
          },
          component:()=>import(`@/views/hr/personnelTransfer`)
        },
        {
          path:"/leaveFiles",
          name:"leaveFiles",
          meta:{
            title:'离职档案'
          },
          component:()=>import(`@/views/hr/leaveFiles`)
        },
        {
          path:"/stampingControl",
          name:"stampingControl",
          meta:{
            title:'印章管理'
          },
          component:()=>import(`@/views/publicAdministration/stampingControl`)
        },
        {
          path:"/vehicleManagement",
          name:"vehicleManagement",
          meta:{
            title:'车辆管理'
          },
          component:()=>import(`@/views/publicAdministration/vehicleManagement`)
        },
        {
          path:"/meetingManagement",
          name:"meetingManagement",
          meta:{
            title:'会议室管理'
          },
          component:()=>import(`@/views/publicAdministration/meetingManagement`)
        },
        {
          path:"/announcementType",
          name:"announcementType",
          meta:{
            title:'公告类型'
          },
          component:()=>import(`@/views/corporateAnnouncements/announcementType`)
        },
        {
          path:"/announcementList",
          name:"announcementList",
          meta:{
            title:'公告列表'
          },
          component:()=>import(`@/views/corporateAnnouncements/announcementList`)
        },
        {
          path:"/iStarted",
          name:"iStarted",
          meta:{
            title:'我发起的'
          },
          component:()=>import(`@/views/officeExamine/iStarted`)
        },
        {
          path:"/iDealed",
          name:"iDealed",
          meta:{
            title:'我处理的'
          },
          component:()=>import(`@/views/officeExamine/iDealed`)
        },
        {
          path:"/iCopied",
          name:"iCopied",
          meta:{
            title:'抄送给我的'
          },
          component:()=>import(`@/views/officeExamine/iCopied`)
        },
        {
          path:"/accessConfiguration",
          name:"accessConfiguration",
          meta:{
            title:'权限配置'
          },
          component:()=>import(`@/views/financialManagement/accessConfiguration`)
        },
        {
          path:"/reimburseStarted",
          name:"reimburseStarted",
          meta:{
            title:'报销管理-我申请的'
          },
          component:()=>import(`@/views/financialManagement/reimburseManagement/reimburseStarted`)
        },
        {
          path:"/reimburseDealed",
          name:"reimburseDealed",
          meta:{
            title:'报销管理-我处理的'
          },
          component:()=>import(`@/views/financialManagement/reimburseManagement/reimburseDealed`)
        },
        {
          path:"/reimburseCopied",
          name:"reimburseCopied",
          meta:{
            title:'报销管理-抄送给我的'
          },
          component:()=>import(`@/views/financialManagement/reimburseManagement/reimburseCopied`)
        },
        {
          path:"/reimburseRemit",
          name:"reimburseRemit",
          meta:{
            title:'报销管理-打款(管理专用)'
          },
          component:()=>import(`@/views/financialManagement/reimburseManagement/reimburseRemit`)
        },
        {
          path:"/invoiceStarted",
          name:"invoiceStarted",
          meta:{
            title:'发票管理-我申请的'
          },
          component:()=>import(`@/views/financialManagement/invoiceManagement/invoiceStarted`)
        },
        {
          path:"/invoiceDealed",
          name:"invoiceDealed",
          meta:{
            title:'发票管理-我处理的'
          },
          component:()=>import(`@/views/financialManagement/invoiceManagement/invoiceDealed`)
        },
        {
          path:"/invoiceCopied",
          name:"invoiceCopied",
          meta:{
            title:'发票管理-抄送给我的'
          },
          component:()=>import(`@/views/financialManagement/invoiceManagement/invoiceCopied`)
        },
        {
          path:"/invoiceRemit",
          name:"invoiceRemit",
          meta:{
            title:'发票管理-打款(管理专用)'
          },
          component:()=>import(`@/views/financialManagement/invoiceManagement/invoiceRemit`)
        },
        {
          path:"/accountManagement",
          name:"accountManagement",
          meta:{
            title:'到账管理'
          },
          component:()=>import(`@/views/financialManagement/accountManagement`)
        },
        
        // 新增
        // 系统管理
        {
          path:"/userManagement",
          name:"userManagement",
          meta:{
            title:'用户管理'
          },
          component:()=>import(`@/views/isystem/userManagement`)
        },
        {
          path:"/roleUserList",
          name:"roleUserList",
          meta:{
            title:'角色管理'
          },
          component:()=>import(`@/views/isystem/roleUserList`)
        },
        {
          path:"/permission",
          name:"permission",
          meta:{
            title:'菜单管理'
          },
          component:()=>import(`@/views/isystem/permission`)
        },
        {
          path:"/tenant",
          name:"tenant",
          meta:{
            title:'租户管理'
          },
          component:()=>import(`@/views/isystem/tenant`)
        },
        {
          path:"/depart",
          name:"depart",
          meta:{
            title:'部门管理'
          },
          component:()=>import(`@/views/isystem/depart`)
        },
        {
          path:"/position",
          name:"position",
          meta:{
            title:'职务管理'
          },
          component:()=>import(`@/views/isystem/position`)
        },
        {
          path:"/departUserList",
          name:"departUserList",
          meta:{
            title:'我的部门'
          },
          component:()=>import(`@/views/isystem/departUserList`)
        },
        {
          path:"/addressList",
          name:"addressList",
          meta:{
            title:'通讯录'
          },
          component:()=>import(`@/views/isystem/addressList`)
        },
        {
          path:"/dict",
          name:"dict",
          meta:{
            title:'数据字典'
          },
          component:()=>import(`@/views/isystem/dict`)
        },
        {
          path:"/category",
          name:"category",
          meta:{
            title:'分类字典'
          },
          component:()=>import(`@/views/isystem/category`)
        },
        {
          path:"/annountCement",
          name:"annountCement",
          meta:{
            title:'系统通告'
          },
          component:()=>import(`@/views/isystem/annountCement`)
        },
        {
          path:"/newPermissionList",
          name:"newPermissionList",
          meta:{
            title:'菜单管理2'
          },
          component:()=>import(`@/views/isystem/newPermissionList`)
        },
        // 系统监控 
        {
          path:"/gatewayroute",
          name:"gatewayroute",
          meta:{
            title:'路由网关'
          },
          component:()=>import(`@/views/isystem/gatewayroute`)
        },
        {
          path:"/QuartzJobList",
          name:"QuartzJobList",
          meta:{
            title:'定时任务'
          },
          component:()=>import(`@/views/isystem/QuartzJobList`)
        },
        {
          path:"/log",
          name:"log",
          meta:{
            title:'日志管理'
          },
          component:()=>import(`@/views/isystem/log`)
        },
        {
          path:"/dataLog-list",
          name:"dataLog-list",
          meta:{
            title:'数据日志'
          },
          component:()=>import(`@/views/isystem/dataLog-list`)
        },
        // 消息管理
        {
          path:"/sysMessageTemplateList",
          name:"sysMessageTemplateList",
          meta:{
            title:'模板管理'
          },
          component:()=>import(`@/views/message/sysMessageTemplateList`)
        },
        {
          path:"/sysMessageList",
          name:"sysMessageList",
          meta:{
            title:'消息管理'
          },
          component:()=>import(`@/views/message/sysMessageList`)
        },
        {
          path:"/userAnnouncement",
          name:"userAnnouncement",
          meta:{
            title:'我的消息'
          },
          component:()=>import(`@/views/message/userAnnouncement`)
        },
      ]
    }

  ]
})
RouterList.beforeEach((to , from , next)=>{
  // console.log(from)//你从哪一个路由
  // console.log(to);//你去哪一个路由
  // 如果to的路由对象不是登录注册忘记密码等不需要登录的页面&& 用户没有登录（没有token）我们就返回登录页
  // 如果用户已经登录但是用户将要访问项目模块的权限不足我们就返回404页面
  // 如果from是null但是to是需要登录的页面 我们直接跳转到登录页
  if(from.name&&to.meta.title !="金氏后台登录页面"){
    let isRepeat=0;
    let navList = GetCookie("navList")?JSON.parse(GetCookie("navList")):[];
    let data ={
      path:to.path,
      title:to.meta.title,
      ischoose:false  //面包屑是否选中状态
    };
    for(let index in navList){
      if(navList[index].path==data.path){isRepeat=1}
    };
    if(!isRepeat){
      navList.push(data);
      console.log(navList);
      SetCookie("navList",JSON.stringify(navList))
    };
    isRepeat=0;
    // 存点击路由的面包屑跳转
    SetCookie("editableTabsValue",data.path)
  }
    // from.path 
    // from.meta.title
  next()//放行
})
RouterList.afterEach((to , from)=>{
  // console.log(to)//你去哪一个路由
  // console.log(from)//你去哪一个路由
  // 进入页面之后第一时间Load的加载性动画进行加载
  document.title = to.meta.title;

})
export default RouterList;